Repository navigation
Conversation
extract_response only accepted a string message.content. OpenAI returns content: null with the model's refusal text in message.refusal, and several OpenAI-compatible providers return content as a list of parts. Both shapes raised ValueError, so the attempt was recorded as an error (exit code 2) instead of being classified - a refusal was reported as a broken target. Accept the refusal text when content is null, and join the text of text/output_text parts. Messages with no usable text still raise. Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
extract_responsein the harness only accepts a stringchoices[0].message.content. Two common OpenAI-compatible response shapes are rejected withValueError("Expected text content in response"):"content": nullwith the refusal text inmessage.refusal.contentas a list such as[{"type": "text", "text": "..."}].attempt()catches the exception and records the attempt aserror, soresult_codereturns 2. In a security harness that is the worst case: an explicit refusal gets reported as a broken target instead of being classified.Fix
A small
_message_texthelper:contentwhen it is a string (unchanged);textoftext/output_textparts whencontentis a list;message.refusalwhencontentisnullandrefusalis a non-empty string.Anything else still raises, so the malformed-choices tests from #400 keep passing. That includes
{"content": None}with no refusal, empty or non-text part lists, and non-string content.Tests
New cases in
tests/harness/test_response_parsing.pycover the refusal field, the content-part join, and the shapes that must still be rejected.pytest tests/harness: 75 passed. Without theloop.pychange, the two new positive tests fail. black is clean, and ruff reports the same findings before and after the change (all pre-existing).AI-assisted change. I reviewed it and ran the tests locally.